package com.coins.common.redis;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

/**
 * 功能：缓存数据
 */
@Component("redisManagers")
@SuppressWarnings("serial")
public class RedisManagers implements Serializable {

	@Autowired
	protected RedisTemplate<byte[], byte[]> redisTemplate;

	public RedisTemplate<byte[], byte[]> getRedisTemplate() {
		return redisTemplate;
	}

	public void setRedisTemplate(RedisTemplate<byte[], byte[]> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	public void pubMessage(Object data) {
		this.redisTemplate.convertAndSend("coins:handler:events", JSONObject.toJSON(data));
	}

	public void sendMessage(String channel, Serializable message) {
		this.redisTemplate.convertAndSend(channel, message);
	}

	protected RedisSerializer<String> getRedisSerializer() {
		return redisTemplate.getStringSerializer();
	}
}
